{extend name="common/application" /}
{block name="title"}<title>搜索中心-人才搜索</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/slide.css">
<link rel="stylesheet" type="text/css" href="_CSS_/train.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/search_work.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/scom.css"/>
<style>
    #button {
        cursor: pointer;
    }
</style>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
{/block}


{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix" style="padding-top: 0px;">
        <div class="personnels sectionArea normalBox" style="margin-top: 0px;">
            <!--人才分类-->
            <div class="courseMenu">
                {include file="/common/course" /}
                <input type="hidden" value="" id="all">
                <input type="hidden" value="" id="value">
                <input type="hidden" value="" id="index">
                <div class="sortItem normalBox">
                    <div class="sorts main-sort">
                        <label class="fl">人才分类：</label>
                        <div class="serviceSort fl">
                            <div class="serviceBox mains fl">
                                <a class="mainSort choosed" all="0" href="javascript:;">全部人才</a>
                                <a class="mainSort" all="1" href="javascript:;">企业管理人才</a>
                                <a class="mainSort" all="2" href="javascript:;">服务业人才</a>
                                <a class="mainSort" all="3" href="javascript:;">高层次人才</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="personSelect normalBox clearfix">
                    <!--省份选择-->
                    <div class="citySelect fr">
                        <label for="city">选择省份：</label>
                        <select id="city"></select>
                    </div>
                    <!--工作单位-->
                    <div class="jobSelect fl">
                        <label for="job">工作单位：</label>
                        <input class="fillJob" type="text" value="" placeholder="请输入工作单位" id="job"/>
                        <input type="button" id="button" value="确定">
                    </div>
                </div>
                <div class="serviceHeader">
                    <div class="serviceNavi fl">
                        <a class="sortType active" value="0" href="javascript:;">综合</a>
                        <a class="sortType" value="1" href="javascript:;">最新</a>
                        <a class="sortType" value="2" href="javascript:;">最热</a>
                    </div>
                    <div class="total fr">
                        <p class="mr20">共<span class="num" id="count"></span>个人才</p>
                        <a class="prev" href="javascript:;">
                            <span class="icons icon-prev hide"></span>
                            <span class="icons icon-grey-prev"></span>
                        </a>
                        <p><span class="currentPage">1</span>/<span class="allPage"></span></p>
                        <a class="next" href="javascript:;">
                            <span class="icons icon-next"></span>
                            <span class="icons icon-grey-next hide"></span>
                        </a>
                    </div>
                </div>
            </div>
            <div class="conBody">
            </div>
            <!--分页-->
            <div id="page"></div>
        </div>
    </div>
</div>

{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/jquery.SuperSlide.2.1.2.js"></script>
<script type="text/javascript">
    $('#sel_4').addClass('selected');
    $("a.selectType").eq(0).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_work')}?" + keyword;
    });
    $("a.selectType").eq(1).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_trade')}?" + keyword;
    });
    $("a.selectType").eq(2).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_store')}?" + keyword;
    });
    $("a.selectType").eq(3).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_courses')}?" + keyword;
    });
    $("a.selectType").eq(4).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_persons')}?" + keyword;
    });
    $("a.selectType").eq(5).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_teachers')}?" + keyword;
    });
    $("a.selectType").eq(6).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_government')}?" + keyword;
    });


    $(function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
		$("#keyword").val(keyword);
        if (keyword == 'undefined') {
            keyword = null;
        }
        postfile(1, keyword);
        $.ajax({
            type: 'get',
            url: "{:url('api/keyword/get_province')}",
            dataType: 'jsonp',
            success: function (msg) {
                if (msg.code == 200) {
                    $("#city").html('');
                    var html = '<option value="0">请选择</option>';
                    for (var i = 0; i < msg.data.length; i++) {
                        html += '<option value="' + msg.data[i].id + '">' + msg.data[i].province + '</option>';
                    }
                    $("#city").html(html);
                }
            }
        })
    });



    $('.prev').on('click', function () {
        var type = $("#all").val();
        var category = $("#city").val();
        var index = $("#job").val();
        var value = $(this).attr('value');
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var prev_num = parseInt($('.currentPage').html()) - 1;
        if (prev_num != 0) {
            postfile(prev_num, keyword, category, value, type, index);
        }
    });
    $('.next').on('click', function () {
        var type = $("#all").val();
        var category = $("#city").val();
        var index = $("#job").val();
        var value = $(this).attr('value');
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var next_num = parseInt($('.currentPage').html()) + 1;
        var max_num = parseInt($('.allPage').html());
        if (next_num <= max_num) {
            postfile(next_num, keyword, category, value, type, index);
        }
    });

    $(".sortType").on('click', function () {
        $('.sortType').removeClass('active');
        $(this).addClass('active');
        var index = $(this).attr('value');
        $("#index").val(index);
        var type = $("#all").val();
        var category = $("#city").val();
        var value = $("#job").val();
        var keyword = decodeURI(window.location.href.split("?")[1]);
        postfile(1, keyword, category, value, type, index);
    });


    $(".mainSort").on('click', function () {
        $('.mainSort').removeClass('choosed');
        $(this).addClass('choosed');
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var type = $(this).attr('all');
        $("#all").val(type);
        var category = $("#city").val();
        var value = $("#job").val();
        var index = $("#index").val();
        postfile(1, keyword, category, value, type, index);
    });

    $("#button").click(function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var type = $("#all").val();
        var category = $("#city").val();
        var value = $("#job").val();
        var index = $("#index").val();
        postfile(1, keyword, category, value, type, index);
    });

    // 交易方式
    $("#city").change(function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var type = $("#all").val();
        var category = $("#city").val();
        var value = $("#job").val();
        var index = $("#index").val();
        postfile(1, keyword, category, value, type, index);
    });


    function postfile(page, keyword, category, value, type, index) {
        $.ajax({
            type: 'get',
            url: "{:url('api/keyword/search_persons')}",
            data: {
                'page': page,
                'keyword': keyword,
                'area': category,
                'workplace': value,
                'label': type,
                'value': index
            },
            dataType: 'jsonp',
            success: function (msg) {
                if (msg.code == 200) {
                    $('.num').html(msg.data.count);
                    $('.currentPage').html(page);
                    var pages = Math.ceil(msg.data.count / 18);
                    $('.allPage').html(pages);
                    $("#count").html(msg.data.count);
                    //相关人才
                    var re = /^[0-9]+$/;
                    if (msg.data.count == 0) {
                        var personnel = '<div class="nodatas normalBox">' +
                            '<img src="/static/web/images/nodata.png"/>' +
                            '<p>抱歉，找不到相关数据</p></div>';

                        $(".conBody").html(personnel);
                    } else {
                        var personnel = "";//人才
                        for (var w = 0; w < msg.data.personnel.length; w++) {
                            var arr = msg.data.personnel[w].label.split(" ");
                            var label = "";
                            for (var m = 0; m < arr.length; m++) {
                                if (arr[m]) {
                                    label += '<span class="labels">' + arr[m] + '</span>';
                                }
                            }
                            if (re.test((w + 1) / 3)) {
                                personnel += '<div class="personInfo sectionItem mr0">';
                            } else {
                                personnel += '<div class="personInfo sectionItem">';
                            }
                            personnel += '<div class="userImg"><a class="links" href="/index.php/index' +
                                '/train/persons_details.html?type=1&id=' + msg.data.personnel[w].id + '">' +
                                '<img src="/static/web/images/76.png" class="icon-wapper">' +
                                '<img src="/Images/Talent/' + msg.data.personnel[w].img_url + '" class="icon"></a></div>' +
                                '<a class="links username" href="/index.php/index' +
                                '/train/persons_details.html?type=1&id=' + msg.data.personnel[w].id + '">' + msg.data.personnel[w].talentname + '</a>' +
                                '<p class="position">' + msg.data.personnel[w].rolename + '</p>';
                            personnel += '<p class="position">' + label + '</p>';
                            personnel += '<div class="areas moreline" limit="54">' + msg.data.personnel[w].field + '</div></div>';
                        }
                        $(".conBody").html(personnel);
                        if (msg.data.personnel.length == 0) {
                            $('#page').html('');
                        } else {
                            $('#page').html(msg.data.render);
                            $("#pagination").delegate("a", "click", function () {
                                var num = $(this).attr("num");
                                var type = $("#all").val();
                                var category = $("#city").val();
                                var value = $("#job").val();
                                var index = $("#index").val();
								
                                if (num) {
                                    postfile(num, keyword, category, value, type, index);
                                }
								
                            });
							$("#GO").on('click',function(){
								var king = $("#go").val();
								if(king > pages){
									layer.alert("最多输入"+pages+"页");
									return;
								}
								postfile(king, c_id, category, value);
							});
                        }
                    }
                }
                /*限制字符个数*/
                $(".moreline").each(function () {
                    var val = $(this).attr('limit');
                    var maxwidth = val;
                    if ($(this).text().length > maxwidth) {
                        $(this).text($(this).text().substring(0, maxwidth));
                        $(this).html($(this).html() + '...');
                    }
                });
            }
        })
    }
</script>
{/block}